using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Core.Items;

namespace Core.Persistence
{
    public class SqlPersistence : IPersistence
    {
        #region IPersistence Members

        private string _connectionString = "Data Source=NOTEBOOK\\SQLEXPRESS;Initial Catalog=ToDoPersonal;Integrated Security=True";

        public Guid GetRootElementId(string username)
        {
            Guid retVal = Guid.Empty;

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                command.CommandText = string.Format("SELECT itemId FROM Users WHERE id = '{0}'", username);
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    retVal = reader.GetGuid(0);
                }
            }
            return retVal;
        }

        public Guid Login(string username, string password)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public ToDoItem GetItem(Guid id)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void StoreItem(ToDoItem item)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void MoveItem(Guid item, Guid oldParent, Guid newParent)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public void DeleteItem(ToDoItem item)
        {
            throw new Exception("The method or operation is not implemented.");
        }



        #endregion

        #region IPersistence Members


        public void UpdateItem(ToDoItem item)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}
